<#include "/template/_ListPageWithTree.html" />
<#assign left_title="部门列表"> 
<@left>
<ul id="lefttree" class="easyui-tree" url="${root!}/framedept/leftTree"></ul>
<script type="text/javascript">
			$(function(){
				$('#lefttree').tree({
					onClick:function(node){
						$('#dg').datagrid({
							url:'${root!}/framedept/table?code='+node.attributes.deptCode
						});
					}
				});
			});
</script>
</@left> 
<@center>
<table id="dg" toolbar="#tb">
	<thead>  
            <tr>  
                <th data-options="field:'ck',checkbox:true"></th>  
                <th data-options="field:'deptName',width:0.3,formatter:editName">部门名称</th>  
                <th data-options="field:'isreal',width:0.3,formatter:realDept">真实部门</th>  
                <th data-options="field:'order',width:0.2">排序号</th>
                <th data-options="field:'id',hidden:true"></th>
            </tr>  
        </thead> 
</table>
<div id="tb" style="height:auto">
	<div style="margin-bottom: 5px;border-bottom: 1px solid #ddd;">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
			onclick="addDept();">新增部门</a> 
		<a href="#" class="easyui-linkbutton" onclick="deleteDept()"
			data-options="plain:true,iconCls:'icon-cancel'">删除选中</a>
	</div>
</div>

<script type="text/javascript">

$(function(){
	$('#dg').datagrid({  
	    url:'${root!}/framedept/table',
	    rownumbers:true,
	    pagination:true,
	    fitColumns: true,/*自动扩大或缩小列的尺寸以适应表格的宽度并且防止水平滚动*/
	    pageSize : ${tableSize!},
	    onDblClickRow:function(){
			editDept();
		},
		fit:true,
		checkbox:true,
		singleSelect:true,
		selectOnCheck:false
	});
});

function addDept(){
	var node = $('#lefttree').tree('getSelected');
	var parent="";
	if(node){
		parent = node.id;
	}
	OpenDialogRefreshParent("${root!}/framedept/add?parentId="+parent,"","500","300");
}

function editDept(id_){
	var id = id_?id_:$('#dg').datagrid("getSelected").id;
	OpenDialogRefresh("${root!}/framedept/edit/"+id,"","500","500");
	
}

function editName(val,row){
	return '<a href="#" onclick="editDept(\''+row.id+'\')">'+val+'</a>';
}

function realDept(val,row){
	var check = val?"checked":"";
	return '<input type="checkbox" '+check+' >';
}


function deleteDept(){
	var rows = $('#dg').datagrid("getChecked");
	if(rows.length==0){
		alert("未选择数据");
	}else{
		var ids=StringUtil.array2Str(rows,"id",";");
		$.ajax({
			url:"${root!}/framedept/delete?ids="+ids,
			type:"GET",
			dataType:"json",
			success:function(){
				window.location=window.location.href.replace("#","");
			}
		});
	}
}


</script>
</@center>
